<?php
define("DEPLOYED",false);
require "global.php";

$arr_user = array();$arr_pass = array();
$fp = fopen("mail_address.txt","r");
while($line=fgets($fp,1024)){
	list($arr_user[],$arr_pass[]) = explode("|", $line);
}
$i=0;
foreach($arr_user as $user){
	echo $user.'->'.$arr_pass[$i++];
}

$mail_number = count($arr_user);

$title = "双11来了，错过1天等1年，淘宝天猫优选商品半价大优惠！";

$sort_arr = explode(",", "女装,,手机数码,家居");

$body = "亲！<br/>　　我们为您精选了双11半价商品，请点击商品名称或备用网址进行抢购！<br/>　　<a href='http://t.cn/zjhi3wX'>查看所有半价商品，请猛击这里</a>！<br/><br/>";
$head ="<table border='0' cellspacing='10px'>";
$head .= "<tr bgcolor='#eeeeee'><td>品牌</td><td>商品</td><td>专柜价</td><td>双11狂欢价</td><td>备用网址</td></tr>";
$line = "";

$pro_db = new PormotionDB();

foreach($sort_arr as $sort){
	$list = $pro_db->getSortPromotionList($sort);
	foreach($list as $row){
		$aline = "<tr><td>".$row['brand_name'].'</td><td><a href="'.$row['baidu_url'].'" target="_blank">'.$row['goods_title'].'</a></td><td>'.$row['price'].'</td><td>'.$row['off_price'].'</td><td><a href="'.$row['weibo_url'].'" target="_blank">'.$row['weibo_url'].'</a></td></tr>';
		echo iconv('utf-8','gbk',$aline).PHP_EOL;
		$line .= $aline;
	}
}
$line .= "</table>";

$body = $body.$head.$line;

$fp = fopen("qqmail.log","a+");

$qqlist = $pro_db->getMailList();
$t = 0;
foreach($qqlist as $qq){
	list($msec, $sec) = explode(' ', microtime());
	srand($sec);
	$pos = rand(0,$mail_number-1);
	$t++;
	if($t<=450) continue;
	$user = trim($arr_user[$pos]);
	$endpoint = substr($user,strpos($user,"@")+1);
	echo 'mail:'.$arr_user[$pos].' '.$arr_pass[$pos].PHP_EOL;	
	$mailList = array($qq['address']);
	$result = 0;
	$qqmail = new QQMail("smtp.126.com", trim($arr_user[$pos]), trim($arr_pass[$pos]), trim($arr_user[$pos]));
	$result = $qqmail->send(iconv('utf-8','gbk',$title), $mailList , iconv('utf-8','gbk',$body));
	$line = strftime("%Y-%m-%d %H:%M:%S",time()) .':'.'     '. $qq['address'].' send '.$result.'!'.PHP_EOL;
	echo $line;
	fwrite($fp,$line);
	if($result==0) sleep(100);
	else sleep(2);
}

fclose($fp);

?>